﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HCFramework.API.LINQ;

namespace HCFramework.Product.FrontEndControl
{
    public partial class FilterByManufacturer : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();

                if (M.UrlQuery.manufacturerID.HasValue)
                {
                    cboFilter.ClearSelection();
                    cboFilter.SelectedValue = M.UrlQuery.manufacturerID + "";
                }
            }
        }

        private void BindData()
        {
            HCDataContext db = new HCDataContext();
            List<Manufacturer> listManufacturer = db.Manufacturers.OrderBy(ik=>ik.OrderDisplay).ToList();

            cboFilter.DataTextField = "Name";
            cboFilter.DataValueField = "ManufacturerID";
            cboFilter.DataSource = listManufacturer;
            cboFilter.DataBind();

            cboFilter.Items.Insert(0, new ListItem(M.Common.GetLang("Tất cả"), ""));
        }
    }
}